package com.doudoukeji.service.Receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.doudoukeji.service.Activity.ConstantValue;
import com.doudoukeji.service.Activity.Login.loginActivity;
import com.doudoukeji.service.Bean.Token;
import com.doudoukeji.service.Utils.DataCleanManager;
import com.doudoukeji.service.Utils.LoaderImage;
import com.doudoukeji.service.Utils.MyToast;
import com.doudoukeji.service.Utils.SharedPreferencesUtils;

/**
 * XMPP 退出登录广播
 *
 * @author nseer
 */
public class xmppReceier extends BroadcastReceiver {
    private Context context;


    @Override
    public void onReceive(Context context, Intent intent) {
        this.context = context;
        String action = intent.getAction();
        if (action.equals(ConstantValue.goToLogin)) {
            String message = intent.getStringExtra("message");
            String msgType = intent.getStringExtra("msgType");
            if (ConstantValue.OGTOLOGINCODE.equals(msgType)) {
                intent = new Intent(context, loginActivity.class);
                intent.putExtra("isshowdialog", "show");
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                context.startActivity(intent);
                MyToast.DefaultmakeText(context, message, 1);
                DataCleanManager.cleanExternalCache(this.context);
                DataCleanManager.cleanInternalCache(this.context);
//                SharedPreferencesUtils.setParam(this.context, "READ", "0");
                LoaderImage.clearCache();
                Token.logout();
            }
        }

    }

//	private boolean serviceIsRunning() {
//		ActivityManager manager = (ActivityManager) context
//				.getSystemService(Context.ACTIVITY_SERVICE);
//		for (ActivityManager.RunningServiceInfo service : manager
//				.getRunningServices(Integer.MAX_VALUE)) {
//			if (SERVICE_CLASSNAME.equals(service.service.getClassName())) {
//				LogUtil.info("MQTTService�ѿ���===true",
//						ConstantValue.currentStage);
//				return true;
//			}
//		}
//		LogUtil.info("MQTTService�ѹر�===false", ConstantValue.currentStage);
//		return false;
//	}

//    private void stopBlackIceService(Context context) {
//
//        final Intent intent = new Intent(context, FeatMessageServiceDemo.class);
//        context.stopService(intent);
//    }

}
